/**
 * 
 */
package com.estock.crawler.parse;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.nodes.Document;

import com.estock.crawler.utils.ESCrawlerUtil;
import com.estock.crawler.writer.AbstractJqkaStockCsvWriter;
import com.estock.crawler.writer.JqkaStockHomeCsvWriter;

/**
 * Parse content from urls like below: <br><br>
 * 
 * http://basic.10jqka.com.cn/000413/
 * 
 * @author richard
 *
 */
public class JqkaStockHomeParser extends AbstractJqkaStockParser {
	
	@Override
	public List<File> getAllFilesToBeParsed() {
		List<File> results = new ArrayList<File>();
		
		File direcory = new File(ESCrawlerUtil.get10jqkaRawDataDir() + "basic.10jqka.com.cn/"); 
		File[] files = direcory.listFiles();
		
		for (File file : files) {
			if (file.isDirectory() || 
					!file.getName().endsWith(".html")) {
				continue;
			}
			results.add(file);
		}
		
		return results;
	}
	
	@Override
	public AbstractJqkaStockCsvWriter getJqkaStockCsvWriter(String stockcode,
			Document doc) {
		return new JqkaStockHomeCsvWriter(doc, stockcode);
	}

	@Override
	public String getStockCodeFromFile(File file) {
		return file.getName().replace(".html", "");
	}

	@Override
	public String getCsvFilename() {
		return "comSummary.csv";
	}
	
}
